#!/usr/bin/python

import sys
sys.path.append('..')

import mirny, mirny.core, re, gettext, os, cmd, readline
import Pyro, Pyro.core, Pyro.naming, Pyro.protocol

langlist = ['en','fr']
languages = dict([(lang, gettext.translation('mirny', 
		localedir=os.path.join(os.path.dirname(__file__), 'messages'),
		languages=[lang]))
		for lang in langlist])

# default language : en
lang = 'en'
if len(sys.argv) > 1 and sys.argv[1] in langlist:
	lang = sys.argv[1]

languages[lang].install()
manager = mirny.core.Manager()

class CLI(cmd.Cmd):
	prompt = 'mirny> '
	ruler = '-'
	def emptyline(self):
		self.do_status()
	def do_quit(self, arg=None):
		print 'Bye.'
		sys.exit(0)
	def do_status(self, arg=None):
		print 'Not yet implemented'
	def do_list(self, what):
		plugins = manager.list_plugins()
		if what in ['input', 'carve', 'dissect', 'extract', 'filter', 'output']:
			print 'Printing %s plugins :' % what
			ps = [p[0] for p in plugins if p[0]==what]
			if len(ps):
				print '\n'.join(ps)
			else:
				print '(none)'
		else:
			print 'Printing all plugins :'
			ps = [p[0] for p in plugins]
			if len(ps):
				print '\n'.join(ps)
			else:
				print '(none)'
	def do_load(self, what):
		manager.load_plugin(what)
			
	

cli = CLI()
try:
	cli.cmdloop('Welcome to Mirny cli.')
except KeyboardInterrupt:
	print 'quit\nBye.'
	sys.exit(0)

